// 用户信息
<template>
    <a-card :bordered="false">
        <!-- 查询 -->
        <div class="table-page-search-wrapper">
             <a-form layout="inline">
                <a-row :gutter="10">
                <a-col :md="10" :sm="12">
                    <a-form-item label="用户账号" style="margin-left:8px">
                    <a-input placeholder="请输入账号" v-model="queryParam.username"></a-input>
                    </a-form-item>
                </a-col>
                <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                    <a-col :md="6" :sm="24">
                    <a-button type="primary" @click="searchQuery" icon="search" style="margin-left: 18px">查询</a-button>
                    <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
                    </a-col>
                </span>
                </a-row>
            </a-form>
        </div>

         <div class="table-operator" :md="24" :sm="24" style="margin-top: -15px">
            <a-button @click="handleAddUserDepart" type="primary" icon="plus">添加已有用户</a-button>
            <a-button @click="handleAdd" type="primary" icon="plus" style="margin-top: 16px">新建用户</a-button>
            <a-dropdown v-if="selectedRowKeys.length > 0">
                <a-menu slot="overlay">
                    <!-- 取消关联的业务就是 左侧是部门 右侧是用户 用户是属于部门下的 取消关联就是将部门和用户解绑的操作 -->
                    <!-- TODO 暂时就是一个按钮 -->
                <a-menu-item key="1" @click="batchDel">
                    <a-icon type="delete"/>
                    取消关联
                </a-menu-item>
                </a-menu>
                <a-button style="margin-left: 8px"> 批量操作
                <a-icon type="down"/>
                </a-button>
            </a-dropdown>
         </div>

         <!-- table区域 -->
         <div>
             <!-- table的头部选择信息区域 -->
             <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
                 <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
                 <a style="font-weight: 600">{{selectedRowKeys.length}}</a>项
                 <a style="margin-left: 24px" @click="onClearSelected">清空</a>
             </div>

             <!-- 表格 -->
             <a-table 
                ref="table"
                size="middle"
                bordered
                rowKey="id"
                :columns="columns"                                          
                :dataSource="dataSource"
                :pagination="ipagination"
                :loading="loading"
                :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
                @change="handleTableChange">


                <!-- 操作的按钮插槽 -->
                    <span slot="action" slot-scope="text,record">
                        <a @click="handleEdit(record)">编辑</a>
                        <!-- 分割线 -->
                        <a-divider type="vertical" />

                        <a-dropdown>
                            <a class="ant-dropdown-link">
                                更多 <a-icon type="down"/>
                            </a>
                            <a-menu slot="overlay">
                            <a-menu-item>
                              <a href="javascript:;" @click="handleDeptRole(record)">部门角色</a>
                            </a-menu-item>

                            <a-menu-item>
                                <a href="javascript:;" @click="handleDetail(record)">用户详情</a>
                            </a-menu-item>

                            <a-menu-item>
                                <a-popconfirm title="确定取消与选中部门关联吗?" @confirm="() => handleDelete(record.id)">
                                <a>取消关联</a>
                                </a-popconfirm>
                            </a-menu-item>
                      </a-menu>
                        </a-dropdown>
                    </span>
             </a-table>
         </div>

         <!-- 表单区域 -->
         <select-user-form ref="selectUserForm"></select-user-form>
    </a-card>
</template>
<script>
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import {queryDeptUserList} from '@/mock'
import SelectUserForm from '../../common/SelectUserForm.vue'

export default {
    name: 'DeptUserInfo',
    data() {
        return {
            queryParam: {},
            selectedRowKeys: [],
            // 表格的列
            columns: [
                {
                    title: '用户账号',
                    align: "center",
                    dataIndex: 'username'
                },
                {
                    title: '用户名称',
                    align: "center",
                    dataIndex: 'realname'
                },
                {
                    title: '部门',
                    align: "center",
                    dataIndex: 'orgCode'
                },
                {
                    title: '性别',
                    align: "center",
                    dataIndex: 'sex_dictText'
                },
                {
                    title: '电话',
                    align: "center",
                    dataIndex: 'phone'
                },
                {
                    title: '操作',
                    dataIndex: 'action',
                    scopedSlots: {customRender: 'action'},
                    align: "center",
                    width: 150
                }
            ],
            // 表格的数据源
            dataSource: []
        }
    },
    components: { SelectUserForm },
    mixins: [JeecgListMixin],
    methods: {
        handleAddUserDepart() {
            if (this.currentDeptId == '' ) {
                 this.$message.error("请选择一个部门!")
            } else {
                let that = this;
                if(this.$refs.selectUserForm) {
                    this.$nextTick(()=>{
                        // that.$refs.selectUserForm.show();
                        that.$refs.selectUserForm.visible = true;
                        // that.getAction();
                    })
                }

            }
        },
        batchDel() {

        },
        
        handleDeptRole() {},
        handleDetail() {},
        handleDelete() {},
        handleAdd() {},
        searchQuery() {},
        searchReset() {},
        onClearSelected() {},
        getAction() {
         return new Promise(resolve=> {
           queryDeptUserList().then(res=>{
             resolve(res.result);
           })
         })
       }

    }
}
</script>
<style scoped>
  /** Button按钮间距 */
  .ant-btn {
    margin-left: 3px
  }

  .ant-card {
    margin-left: -30px;
    margin-right: -30px;
  }

  .table-page-search-wrapper {
    margin-top: -16px;
    margin-bottom: 16px;
  }
</style>